package com.boilerCloud.service.order;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.boilerCloud.dao.order.OrderDao;
import com.boilerCloud.dao.user.AppUserDao;
import com.boilerCloud.dto.HzlqswPage;
import com.boilerCloud.dto.enums.OrderRecordEnum;
import com.boilerCloud.dto.order.SalesOrder;
import com.boilerCloud.dto.user.AppUser;

@Service
public class OrderServiceImpl implements IOrderService {
	
	@Resource
	private OrderDao dao;
	
	@Resource
	private AppUserDao userdao;
	
	@Override
	public void qryList(SalesOrder order, HzlqswPage<SalesOrder> page)
			throws Exception {
		dao.qryList(order,page);
		
	}

	@Override
	public void handleSalesOrder(SalesOrder order) throws Exception {
		dao.handleSalesOrder(order);
		dao.addOrderRecord(order.getId(),OrderRecordEnum.getName(order.getStatus()),order.getStatus());
		
	}

	@Override
	public void addSalesOrder(SalesOrder order) throws Exception {
		order.setOrderNo(System.currentTimeMillis()+"");
		AppUser user = userdao.getAppUserInfo(order.getUserId());
		if(user != null){
			order.setDealerId(user.getDealerId());
		}
		dao.addSalesOrder(order);
		order =  dao.getOrderByOrderNo(order.getOrderNo());
		dao.addOrderRecord(order.getId(),OrderRecordEnum.getName(1),1);
		
	}
}

